#include "ComponentManager.h"
#include "Component.h"
#include "../XNA.h"


ComponentManager::ComponentManager()
	:mComponentNumber(0)
{
}

ComponentManager& ComponentManager::GetInstance()
{
	static ComponentManager _ComponentManager;

	return _ComponentManager;
}

void ComponentManager::RegistComponent(std::string name, Component*(*create)(Object*))
{
	ComponentInfo info;
	info.Name = name;
	info.Create = create;

	mInfoList.push_back(info);
}


Component *ComponentManager::CreateComponent(Object* inOwner, std::string componentName)
{
	ComponentInfo *info = FindComponent(componentName);
	if (info == NULL)
	{
		::OutputDebugString(TEXT("Component not found\n"));
		return NULL;
	}
	return info->Create(inOwner);
}

ComponentInfo* ComponentManager::FindComponent(std::string name)
{
	ComponentInfo* info = NULL;
	for (int i = 0; i < (int)mInfoList.size(); i++)
	{
		if (mInfoList[i].Name == name)
		{
			info = &mInfoList[i];
			break;
		}
	}
	return info;
}